//
//  ScoreListItemCell.m
//  PlayBall
//
//  Created by Jdd‘s macbook on 13-9-30.
//
//

#import "JddScoreListItemCell.h"
#import "JddScoreViewController.h"
@implementation JddScoreListItemCell
GET_INSTANCE_VIEW_IMPLEMENT(JddScoreListItemCell)

-(IBAction)startAction:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    btn.selected = !btn.selected;
    NSString *favoriteScores = [NSString stringWithFormat:FAVORITE_SCORES, [JddCommonFunction thisDocumentPath]];
    NSString *jczq = [NSString stringWithFormat:@"%d", LOTTERY_TYPE_ID_FOOTBALL];
    NSString *bd = [NSString stringWithFormat:@"%d", LOTTERY_TYPE_ID_BD];
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:favoriteScores];
    if (![[NSFileManager defaultManager] fileExistsAtPath:favoriteScores isDirectory:NO])
        {
        dictionary = [NSMutableDictionary dictionary];
        [dictionary setValue:[[NSMutableDictionary alloc] init] forKey:jczq];
        [dictionary setValue:[[NSMutableDictionary alloc] init] forKey:bd];
        [dictionary writeToFile:favoriteScores atomically:YES];
        }
    NSMutableDictionary *dic = [dictionary objectForKey:self.lotterId];
    NSString *scoreId = [self.dic objectForKey:@"i1"];
    if (btn.selected) {
        [dic setValue:self.dic forKey:scoreId];
        [dictionary setObject:dic forKey:self.lotterId];
    }else{
        [dic removeObjectForKey:scoreId];
    }
    [dictionary writeToFile:favoriteScores atomically:YES];
    
    [self.delegate refreshStartBtn];
}

@end
